package com.terrynoya.fight.test
{
	import flash.display.Graphics;
	import flash.display.Sprite;
	
	public class GridGraph extends Sprite
	{
		private var _intervalWidth:int;
		private var _intervalHeight:int;
		
		private var _width:int;
		private var _height:int;
		
		public function GridGraph(intervalWidth:int = 20,intervalHeight:int = 20,width:int = 400,height:int = 400)
		{
			super();
			this._intervalHeight = intervalHeight;
			this._intervalWidth = intervalWidth;
			this._width = width;
			this._height = height;
			this.updateView();
		}
		
		private function updateView():void
		{
			var g:Graphics = this.graphics;
			g.clear();
			g.lineStyle(1);
			this.drawVerticalLine(g);
			this.drawHorizontalLine(g);
			g.endFill();
		}
		
		private function drawVerticalLine(g:Graphics):void
		{
			var count:int = Math.floor(this._width / this._intervalWidth);
			for (var i:int = 0; i < count; i++) 
			{
				g.moveTo(i * this._intervalWidth,0);
				g.lineTo(i * this._intervalWidth,this._height);
			}
		}
		
		private function drawHorizontalLine(g:Graphics):void
		{
			var count:int = Math.floor(this._height / this._intervalHeight);
			for (var i:int = 0; i < count; i++) 
			{
				g.moveTo(0,i * this._intervalHeight);
				g.lineTo(this._width,i * this._intervalHeight);
			}
		}
	}
}